package main

import (
	"fmt"
	"log"
	"os"
	"sync"

	"gitee.com/xuesongtao/gotool/xfile"
)

func main() {
	tmpDir := "./tmp"
	fp := xfile.NewFilePool()
	defer fp.Close()
	size := 50
	fileCount := 3

	var wg sync.WaitGroup
	for i := 0; i < size; i++ {
		wg.Add(1)
		go func(num int) {
			defer wg.Done()

			fh, err := fp.Get(fmt.Sprintf("%s/test%d.txt", tmpDir, num%fileCount), os.O_CREATE|os.O_APPEND|os.O_RDWR)
			if err != nil {
				log.Println(err)
				return
			}
			defer fp.Put(fh)

			_, err = fh.AppendContent(fmt.Sprintf("我是 go_%d \n", num))
			if err != nil {
				log.Println(err)
			}
		}(i)
	}
	wg.Wait()
	fmt.Println(fp.GetFile2OpenMap())
}
